Skip to content

Address inconsistent behavior on flux_led component#14713

Merged
amelchio merged 7 commits intohome-assistant:devfrom
oblogic7:flux_bug_fix_2
Jun 26, 2018
Merged

Address inconsistent behavior on flux_led component#14713
amelchio merged 7 commits intohome-assistant:devfrom
oblogic7:flux_bug_fix_2

Conversation

@oblogic7
Copy link
Copy Markdown
Contributor

@oblogic7 oblogic7 commented May 31, 2018

Description:

Corrects inconsistent behavior between different versions of Magic Home controllers that was introduced as part of recent PR to separate white level on the flux_led component. Rigorous testing done on two types of Magic Home LED controllers to confirm that behavior is now consistent.

Also adds white only mode that remaps white value to use brightness for instances where only W channel is connected on RGBW controller. This should restore compatibility with Homekit or other components that expect brightness to control white level in these cases.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5470

Correct issue with comparison that was preventing white value slider from being shown.
@oblogic7 oblogic7 mentioned this pull request May 31, 2018
2 tasks
@tadly
Copy link
Copy Markdown
Contributor

tadly commented May 31, 2018

Was about to search for the previous PR to report some issue.

For me, with an rgbw controller, turning it on resets the white channel to 0.
In other words it does not "remember" it's previous value(s) (not sure if this applies to other properties as well).

Will this be fixed with this PR or should I do some more investigating?

@oblogic7
Copy link
Copy Markdown
Contributor Author

oblogic7 commented May 31, 2018 via email

@mikebsec
Copy link
Copy Markdown

mikebsec commented Jun 1, 2018

There is one remaining issue here. White only is a valid use of this controller: https://www.amazon.com/gp/product/B01DY56N8U When wired as white only it no longer changes brightness by the brightness slider, it controls via the white_value slider. That is extremely non-intuitive to someone who can't wade through these merges/PRs. Perhaps it is time to add a "mode: white" to flux_led and properly map white_value <-> brightness for that use case? That would also make it work transparently with homekit. (all of which worked before the changes started on this train) I can always create a template light to accomplish this for myself, but good luck anyone in the future ever figuring that out. Thoughts?

@tadly
Copy link
Copy Markdown
Contributor

tadly commented Jun 1, 2018

@mikebdotorg you can already set mode to one of rgb and rgbw (rgbw being default)
See the docs here

Also, for rgbw controllers you need both sliders as you can control the brightness for the rgb and the w part independently.

@mikebsec
Copy link
Copy Markdown

mikebsec commented Jun 1, 2018

@tadly - Understood for someone that has 'rgb' AND 'w' wires coming out of their controller that need to be modified.

However, the scenario I am describing here is if someone ONLY wires the 'w' channel. The removal of self._bulb.setWarmWhite255(brightness) with PR 13985 does not make sense intuitively. If someone shows up to homeassistant and sets up a white light but is told that brightness doesn't control brightness that's going to be an odd discussion. The Magic Home app itself does this intuitively for the user who only has white setup so it seems odd homeassistant wouldn't do the same.

I'm suggesting for those users that a "mode: white" is created and there is only a single slider called brightness as all other controls do not serve a purpose any longer. There is no rgb wired to control. For those users this change has broken functionality (automations, homekit, etc... that controlled brightness now fail to do so).

@mikebsec
Copy link
Copy Markdown

mikebsec commented Jun 1, 2018

Magic Home for white only for posterity.

image

@oblogic7
Copy link
Copy Markdown
Contributor Author

oblogic7 commented Jun 1, 2018

I added white mode for cases like @mikebdotorg described and tested with the controller he linked. Seems to be working well for me, but would be great if somebody else would kick the tires.

Example config:

    192.168.1.10:
      name: Test LED 2
      mode: "w"

image

@mikebsec
Copy link
Copy Markdown

mikebsec commented Jun 1, 2018

@oblogic7 - thank you! I'll test tonight (MDT) and let you know.

@mikebsec
Copy link
Copy Markdown

mikebsec commented Jun 2, 2018

@oblogic7 - worked great. All functionality as expected. Can dim with brightness slider on white only in hass UI, and with homekit. Config as you stated:

      192.168.1.11:
        name: left_poster
        mode: "w"

Thanks again. Looking forward to this being merged.

@kineticscreen
Copy link
Copy Markdown

kineticscreen commented Jun 6, 2018

I just noticed something else (I'm running 0.70.1)

When you turn the lights on via hassio, they snap on immediately, rather than fade up.
Turning them off has the correct fade out action.

This is only true via home assistant - the Magic Wifi App has the fade behaviour for both on and off events.


# handle RGB mode
else:
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
Copy link
Copy Markdown
Contributor

@pezinek pezinek Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm that calling turn_on(rgb=[5,0,0], brighness=None) will really set the RGB color to [5,0,0] and not to [255,0,0] or anything else deformed by the previous brightness settings you re-use on line 254 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally had a chance to test this and I found some inconsistent behavior. However, it appears that it is not with the handling of the values by the flux component, but some issue with the way the values are passed into turn_on.

I used the following payload to test:

{
  "entity_id": "light.test_led_1",
  "rgb_color": [0,5,0]
}

rgb_color is being converted to hs_color before being passed into the turn_on method. The flux component then uses color_util.color_hs_to_RGB to convert into a tuple of rgb values. This conversion results in 0,255,0 for the payload above instead of the expected 0,5,0. This is the source of the inconsistent behavior that I'm experiencing.

The flux library will only recalculate rgb values if a numeric value is passed for brightness. If None is passed, then it does not recalculate. I am making a change so that existing brightness value is only passed if rgb is None. This should prevent unexpected recalculation of the brightness when brightness is not included on the payload.

I'm not familiar enough with HA internals to know where to fix the hs_color bug mentioned above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oblogic7: Thanks for investigating furhter !
It seems that this breakage that changes rgb_color [0,5,0] to [0,255,0] has been introduced in PR #11288.
@armills: any clues/suggestions how to fix that ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After digging through the discussion on #11288, I see that @amelchio calls out this bug specifically.

https://github.com/home-assistant/home-assistant/pull/11288/files/1ee6a9f786c0508a7079aa2eaf282e03b2b83c9d#r175284144

I'm still checking out the changes, but I don't think the fix will be implemented on components unless there have been updates since that PR was merged. Maybe a new method has been added that I haven't found yet? If not, it looks to me like it will require more changes to the conversion methods.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Popping in because I was tagged. I did not read all of these comments and I don't have flux_led hardware. Still, if you have specific questions about how things should work, I might be able to help.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amelchio Are you aware of a fix or work around for the issue that you point out here: https://github.com/home-assistant/home-assistant/pull/11288/files/1ee6a9f786c0508a7079aa2eaf282e03b2b83c9d#r175284144

If not, do you know if it will be a component level change or if it will be more involved?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After #11288, the intention is that rgb_color no longer changes the brightness. So turn_on(rgb=[5,0,0], brighness=None) and turn_on(rgb=[255,0,0], brighness=None) should act in the same way: set the light to red with the current brightness level.

This must be implemented in each light platform, like flux_led.py in this case, and

       if brightness is None:
            brightness = self.brightness

seems like a reasonable way to achive that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. That is how it was implemented. I will roll back the last change so that the current brightness is used. Thanks!

@pezinek
Copy link
Copy Markdown
Contributor

pezinek commented Jun 6, 2018

... as well would you mind to update the tests so they check the behaviour you broke in your previous PR's and are trying to fix in this one ?

@oblogic7
Copy link
Copy Markdown
Contributor Author

@pezinek The differences were in the library methods that were being used and different versions of the controllers handling the calls differently. I'm not sure what decreased the coverage though. Will check that out.

self._bulb.setRgb(*tuple(rgb), brightness=brightness)

if not self.is_on:
self._bulb.turnOn()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that self._bulb.getRgb() works even when the bulb is not turned on?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does.

Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

It seems that all comments have been addressed so I will merge this tomorrow if nobody objects.

@kineticscreen
Copy link
Copy Markdown

Seems this didn't make it into 0.72.1

@amelchio amelchio merged commit 15af6b1 into home-assistant:dev Jun 26, 2018
@ghost ghost removed the in progress label Jun 26, 2018
@amelchio
Copy link
Copy Markdown
Contributor

Now merged. This is tricky enough that it should get some beta testing so I will not tag it for a hotfix.

@balloob balloob mentioned this pull request Jul 6, 2018
@kineticscreen
Copy link
Copy Markdown

kineticscreen commented Jul 8, 2018

Well done, this mostly works.

The only problem I'm observing is that the units when sent a 'scene state' from being off, they ignore the RGB value, and just turn on to their previous state.

A second hit of the scene changes the RGB to the correct values.

@tadly
Copy link
Copy Markdown
Contributor

tadly commented Jul 8, 2018

I've also noticed one more nitpick.

If you have a RGBW controller and:

  1. have brightness > 0
  2. have white value > 0
  3. use the slider to bring brightness down to 0
    => the light switch turns off

In other words, only if both sliders are at 0 the switch should turn off

@oblogic7
Copy link
Copy Markdown
Contributor Author

oblogic7 commented Jul 8, 2018

@kineticscreen Can you post the payload you are using for the service call? Maybe it is related to this?

@tadly This is due to the way that HA couples brightness to on/off. When brightness is 0, HA calls turn_off. I did run into this when making the updates, but could not tell the difference between turn_off being called from the UI or service call vs when HA was calling it because brightness was 0.

@MartinHjelmare
Copy link
Copy Markdown
Member

Please continue troubleshooting in an issue. We don't want discussion or troubleshooting in closed PRs.

@home-assistant home-assistant locked and limited conversation to collaborators Jul 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants